package linkedList;

public class QuestionThree {
    //删除链表中 所有对应的val 并返回头节点
    public ListNode removeElements(ListNode head, int val) {
        ListNode tempHead = new ListNode(0);
        tempHead.next = head;
        ListNode temp = tempHead;
        while(temp.next != null){
            if (temp.next.val == val){
                temp.next = temp.next.next;
            }else {
                temp = temp.next;
            }
        }
        return tempHead.next;
    }


}
